//
//  HWQiDaoDateView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/11.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWQiDaoDateView.h"
#import "HWSignCollectionViewCell.h"
@interface HWQiDaoDateView()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property(strong,nonatomic) UICollectionView *maincollectionView;
@property(strong,nonatomic) NSString *jiluStr;

@end


@implementation HWQiDaoDateView

-(instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        //添加一些UI控件
        [self setupUI];
        
        
    }
    
    return  self;
}

// 刷新数据
- (void)roadRefresh {
    
    [self.maincollectionView reloadData];
    
}



// 设置UI
- (void)setupUI {
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
 //   CGFloat jianju =  (kScreenW - 78*CFLScaleValue*4 -20) / 3;
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    
    self.maincollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0,  kScreenW- (28.5+9+15)*2*CFLScaleValue,24*CFLScaleValue+13+8) collectionViewLayout:layout];
    self.maincollectionView.showsHorizontalScrollIndicator = NO;
    self.maincollectionView.delegate = self;
    self.maincollectionView.dataSource = self;
    self.maincollectionView.backgroundColor = [UIColor clearColor];
  //  self.maincollectionView.backgroundColor = RGB(217, 247, 250);
    //self.maincollectionView.alwaysBounceHorizontal = YES;
    
    
   // self.maincollectionView.contentInset = UIEdgeInsetsMake(6, 10, 6, 10);
    // [self.maincollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];  //  一定要设置
    [self.maincollectionView registerClass:[HWSignCollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];
   // [self.maincollectionView  registerNib:[UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cellID"];
    
    //  [UINib nibWithNibName:@"HWShouYouCollectionViewCell" bundle:nil]
    
    self.maincollectionView.userInteractionEnabled = YES;
    [self  addSubview:self.maincollectionView];
    
    
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataMuArr.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    HWSignCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath];
    
    HWQianDaoModel  *model = self.dataMuArr[indexPath.row];
    cell.datamodel = model;
    
 
   //  cell.backgroundColor =  RGB(217, 247, 250);
   // cell.backgroundColor = [UIColor redColor];
    
    return cell;
    
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(24*CFLScaleValue+17*CFLScaleValue,24*CFLScaleValue+13+8);
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DLog(@"点击精品手游单元格-----%ld",indexPath.row);
    
     HWQianDaoModel  *model = self.dataMuArr[indexPath.row];
    
    if ( [model.sign isEqualToString:@"0"]) {
        
        
        [self.delegate qindaoData:model];
        
        
        
    } else {
      
        
     //   [self.delegate qindaoData:model];
        [MBProgressHUD showError:@"您已签到"];
        
        
    }
    
}




- (void)refreshData {
    
    
    [self.maincollectionView reloadData];
    
    if (self.dataMuArr.count > 0) {
        if (self.jiluStr == nil) {
            NSInteger xuanzhon  =  (self.dataMuArr.count - 3);
            
            
            NSIndexPath *index = [NSIndexPath indexPathForRow:xuanzhon inSection:0];
            [self.maincollectionView  scrollToItemAtIndexPath:index atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
            
              
            self.jiluStr = @"1";
            
        }
    }
    
  
    
//   
//      NSString *uidStr = [NSString stringWithFormat:@"%@",[HWLocallyStoredData getLoginUserID]];
//      NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//      NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uidStr,tStr,@"fsd213ewdsadqwe2121213edsad"];
//      NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
//    
//    
//       DLog(@"MD5 ：%@",signStrMd5);
//    
//      NSDictionary *parametes = @{
//                                        @"ios" : @"1",
//                                        @"ct"  : @"app",
//                                        @"ac" : @"my_sign",
//                                        @"t" : tStr,
//                                        @"sign" :signStrMd5,
//                                        @"uid" :uidStr
//    
//                                       };
//      
//      
//      
//        
//           [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//               
//              
//
//               NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//               if ([codeStr intValue] == 1) {
//              
//                     NSLog(@"%@",response);
//                 
//              
//                    
//                     
//            
//                    
//                     
//                   
//                    
//               } else {
//                   
//                 [MBProgressHUD showError:response[@"message"]];
//                                 
//             
//                   
//               }
//               
//          
//               
//           } failure:^(NSString *error) {
//              // [SVProgressHUD dismiss];
//               
//                [MBProgressHUD showSuccess:@"查询失败"];
//              //  [MBProgressHUD hideHUD];
//               
//               
//           }];
//        

      
      

    
    
    
    
    
    
}
@end
